package homeworks.cjt2010.homework1.internalPackage;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class IOTests {

	private static String CURRENT_DIRECTORY_PATH = "E:\\Java\\java_edu"
			+ "\\eclipse-workspace\\private-java-course\\src\\edu\\java"
			+ "\\javaCourseFMI\\homeworks\\cjt2010\\homework1\\internalPackage\\";

	private static String INPUT_FILE_NAME = "input2.txt";
	private static String OUTPUT_FILE_NAME = "output.txt";

	public static void main(String[] args) {

		File currentDirectory = new File(CURRENT_DIRECTORY_PATH);
		File file1 = new File(currentDirectory, INPUT_FILE_NAME);
		File file2 = new File(currentDirectory, OUTPUT_FILE_NAME);

		//
		load(file1);
		store(file2);

	}

	// unfinished
	public static void load(File f) {
		Scanner input = null;
		try {
			input = new Scanner(f);
			while (input.hasNext()) {
				System.out.println(input.nextLine());
			}

		} catch (FileNotFoundException fnfe) {
			System.out.println("There is a problem with access "
					+ "to AirportSystem data file.");
		} finally {
			if (input != null) {
				input.close();
			}
		}
	}

	public static void store(File file) {
		PrintWriter writer = null;

		try {
			writer = new PrintWriter(file);
			
			writer.println("Hello, ");
			writer.println();
			writer.println("Mister");
			
			writer.flush();
			
		} catch (FileNotFoundException fnfe) {
			System.out.println("There is a problem with access "
					+ "to AirportSystem data file.");
		}finally{
			if(writer!=null){
				writer.close();
			}
		}
	}

}
